﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hired
{
    public partial class askquestion : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                string title = Request.QueryString["title"];
                txtTitle.Text = title;
            }
            else
            {
                Response.Redirect("jslogin.aspx");
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                Question qn = new Question();
                qn.Title = txtTitle.Text;
                qn.Contents = txtContent.Text;
                qn.UserID = User.Identity.Name;
                qn.Timestamp = System.DateTime.Now;
                qn.Category = ddlCategory.Text;

                if (DBQuestion.AddQuestion(qn))
                {
                    Response.Redirect("viewquestions.aspx?category=" + Server.UrlEncode(qn.Category));
                }
            }
        }
    }
}